<?php


class tx_zlib_viewhelper_jquery extends tx_zlib_abstract_viewhelper
{

    /**
     * @var string
     */
    private $version = '1.4.1';

    /**
     * @return tx_zlib_viewhelper_jquery
     */
	public function jquery()
	{
        return $this;
	}

	/**
     * @return tx_zlib_viewhelper_jquery
	 */
	public function enable()
	{
		$relFilePath = $this->getJqueryPath();
	    $prefixId = $this->getHelper()->getPi()->prefixId;
		$GLOBALS['TSFE']->additionalHeaderData[$prefixId] .= "\t<script src=\"" . $relFilePath . "\" type=\"text/javascript\"></script>";
		return $this;
	}

    /**
     * @param string $plugin
     * @return tx_zlib_viewhelper_jquery
     */
    public function enablePlugin($plugin)
    {
        if(in_array($plugin, array('colorbox'))) {
            $relPath  = t3lib_extMgm::siteRelPath('zlib') . "js/jquery/jquery." . $plugin . "-min.js";
            $prefixId = $this->getHelper()->getPi()->prefixId;
            $GLOBALS['TSFE']->additionalHeaderData[$prefixId] .= "\t<script src=\"" . $relPath . "\" type=\"text/javascript\"></script>";
        }
        return $this;
    }

	/**
	 * @return string
	 */
	public function getVersion()
	{
	    return $this->version;
	}

	/**
	 * @param string $version
	 */
	public function setVersion($version)
	{
	    $this->version = $version;
	}

	/**
	 * @return string
	 */
	public function getJqueryPath()
	{
		$relExtPath = t3lib_extMgm::siteRelPath('zlib');
		return $relExtPath . "js/jquery/jquery-" . $this->version . ".min.js";
	}

}


if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/zlib/views/helpers/class.tx_zlib_viewhelper_jquery.php'])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/zlib/views/helpers/class.tx_zlib_viewhelper_jquery.php']);
}
